<?php
class Message_m extends MY_Model{
	
	function __construct(){
		parent::__construct();
		$this->_table = 'business_message';
	}
	
	public function insert($data,$user_array = array()){
		
		foreach($user_array as $i){
			$id = substr(md5(uniqid(rand(), true)),0,7);
			//rand(-100,9999999);//md5($i.date("Y-m-d H:i"));
//			echo $id;
			$data['id'] = $id;//substr(
			$data['user_receive']=$i;
			parent::insert($data);
		}
	}
	
	public function get_all($param = array()){
		
		if(!empty($param['id'])){
			$this->_table = 'business_project_users p';
			$this->db->select('u.display_name,p.user_id,p.important');
			$this->db->join('ser_users u','u.id = p.user_id');	
			$this->db->where('p.id',$param['id']);
		}
		return parent::get_all();
	}
	
	public function get_many_by($params = array()){
		if(!empty($params['user_receive'])){
			$this->db->where('user_receive',$params['user_receive']);
		}
		if(!empty($params['type'])){
			$this->db->where('type',$params['type']);
		}
		return parent::get_all();
	}
	
	public function delete($pid,$user_id){
		$this->db->where('pid',$pid);
		$this->db->where('user_receive',$user_id);
		$this->db->delete($this->_table);
	}
}